{include file="public/_head" /}
<!-- /Navbar -->
<!-- Main Container -->
<div class="main-container container-fluid">
    <!-- Page Container -->
    <div class="page-container">

        <!-- Page Sidebar -->
        {include file="public/_left" /}
        <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li class="active">
                        <i class="fa fa-home"></i>&nbsp;管理员管理
                    </li>
                    <li>管理员列表</li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <a href="{:url('admin/admin/add')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;管理员添加</a>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget">
                            <div class="widget-header">
                                <span class="widget-caption">管理员列表</span>
                                <div class="widget-buttons">
                                   {$admins->render()|raw|replace}
                                </div>
                            </div>
                            <div class="widget-body">
                                <table class="table table-hover table-bordered">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>账户</th>
                                        <th>昵称</th>
                                        <th>邮箱</th>
                                        <th>状态</th>
                                        <th>权限</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    {volist name="admins" id="vol"}
                                    <tbody>
                                    <tr>
                                        <td>{$vol.id}</td>
                                        <td>{$vol.admin_username}</td>
                                        <td>{$vol.admin_nickname}</td>
                                        <td>{$vol.admin_email}</td>
                                        <td>{if $vol.admin_status == 1}正常{else /}禁用{/if}</td>
                                        <td>{if $vol.admin_is_super == 1}超级管理员{else /}普通管理员{/if}</td>
                                        <td>
                                            <!--$vol. 精确的当前某行-->
                                            {if $vol.admin_is_super != 1}
                                             <!--判断当前登录账户是否为超级管理员-->
                                            {if session('admin.admin_is_super') == 1}
                                            {if $vol.admin_status == 1}
                                            <a href="#" class="btn btn-darkorange btn-xs admin-status" dataid="{$vol.id}" status="{$vol.admin_status}">禁用</a>
                                            {else /}
                                            <a href="#" class="btn btn-success btn-xs admin-status" dataid="{$vol.id}" status="{$vol.admin_status}">启用</a>
                                            {/if}
                                            {/if}
                                            {/if}
                                            <a href="{:url('admin/admin/edit',['id' => $vol.id])}" class="btn btn-azure btn-xs">编辑</a>
                                            <a href="#" class="btn btn-danger btn-xs admin-del" dataid="{$vol.id}">删除</a>
                                        </td>
                                    </tr>
                                    </tbody>
                                    {/volist}
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

    </div>
    <!-- /Page Container -->
    <!-- Main Container -->

</div>

{include file="public/_js" /}
<script>
    $(function () {
        //分页；给pagination添加样式
        $('.pagination').addClass('pagination-sm');

        //使用类选择器精确到当前id
        $('.admin-status').click(function () {
            //获取id
            var id = $(this).attr('dataid');
            //获取状态
            var status = $(this).attr('status');
            if (status == 1){
                var msg = '确定禁用?';
            }else {
                var msg = '确定启用？';
            }
            layer.confirm(msg,{
                title:'状态操作',
                icon:3
            },function (index) {
                layer.close(index);
                $.ajax({
                   url:"{:url('admin/admin/status')}",
                   type:'post',
                   data:{id:id,status:status},
                   dataType:'json',
                   success:function (data) {
                       if (data.code == 1){
                           layer.msg(data.msg,{
                              icon:6,
                              time:1200
                           },function () {
                               location.href = data.url;
                           });
                       }else {
                           layer.open({
                              title:'操作失败',
                              content:data.msg,
                              icon:5,
                              anim:6
                           });
                       }
                   }
                });
            });
            return false;
        });

        //管理员删除
        $('.admin-del').click(function () {
            var id = $(this).attr('dataid');
            layer.confirm('确认删除？',{
               title:'管理员删除',
               icon:3
            },function (index) {
                layer.close(index);
                $.ajax({
                   url:"{:url('admin/admin/del')}",
                   type:'post',
                   data:{id:id},
                   dataType:'json',
                   success:function (data) {
                       if (data.code == 1){
                           layer.msg(data.msg,{
                              icon:6,
                              time: 1200
                           },function () {
                               location.href = data.url;
                           });
                       } else {
                           layer.open({
                              title:'删除失败',
                              content: data.msg,
                              icon:5,
                              anim:6
                           });
                       }
                   }
                });
            });
            return false;
        });
    })
</script>
</body>
<!--  /Body -->
</html>
